//
//  StoreServeViewController.m
//  com.modada.new
//
//  Created by ferver7 on 2019/5/29.
//  Copyright © 2019 ferver7. All rights reserved.
//

#import "StoreServeViewController.h"
#import "StoreServeInfoCell.h"
#import "ShareViewPopTool.h"
#import "LineItemCell.h"

@interface StoreServeViewController ()
@property (weak, nonatomic) IBOutlet UITableView *selfTableView;
@property (nonatomic,strong) NSMutableArray *listArr;

@end

@implementation StoreServeViewController
-(void)shareAction:(UIButton *)sender
{
   
    [[ShareViewPopTool new]shareDoorType:1 andActivityInfo:@{@"typeInt":@"1"}];//店铺
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self customNavigationItems];
    mNavitationTitle(@"摩嗒嗒 一站式服务");
    [self addRightBarButtonItemWithTitle:@"分享" action:@selector(shareAction:)];
    self.view.backgroundColor = [UIColor AxcUI_colorWithHexCode:@"#EBEBEB"];
    UIImageView * headerImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, mScreenWidth, mScreenWidth*3/8)];
    headerImage.image = mImageByName(@"storeserver");
    self.selfTableView.tableHeaderView = headerImage;
    self.listArr = [[NSMutableArray alloc]init];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 1) {
        return 2+self.listArr.count;
    }
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        StoreServeInfoCell * ssic = mGetTableViewCell(@"storeServeInfoCell");
        [ssic.doorImage sd_setImageWithURL:[NSURL URLWithString:[AppUserBaseModel sharedUserData].doorImage]];
        ssic.storeImageLabel.text = [AppUserBaseModel sharedUserData].storeName;
        ssic.addressLabel.text = [AppUserBaseModel sharedUserData].detailedAddress;
        return ssic;
    }
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            UITableViewCell * titleCell = mGetTableViewCell(@"titleCell");
            return titleCell;
        }else if (indexPath.row == 1) {
            LineItemCell * lineItemCell = mGetTableViewCell(@"lineItemCell");
            lineItemCell.priceLabel.textColor = [UIColor AxcUI_colorWithHexCode:@"#333333"];
            lineItemCell.nameLabel.text = @"项目";
            lineItemCell.priceLabel.text = @"价格";
            lineItemCell.toPriceLabel.text = @"上门服务费";
            return lineItemCell;
        }else{
            LineItemCell * lineItemCell = mGetTableViewCell(@"lineItemCell");
            lineItemCell.priceLabel.textColor = mContentHighlightColor;
            NSDictionary * infoDic = self.listArr[indexPath.row -2];
            lineItemCell.nameLabel.text = infoDic[@"project"];
            lineItemCell.priceLabel.text = [NSString stringWithFormat:@"¥%@",infoDic[@"price"]];
            lineItemCell.toPriceLabel.text = [NSString stringWithFormat:@"¥%@",infoDic[@"servicePrice"]];
            return lineItemCell;
        }
    }
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 120;
    }
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            return 44;
        }else if (indexPath.row == 1) {
            return 44;
        }else{
            NSDictionary * infoDic = self.listArr[indexPath.row -2];
            return [tableView fd_heightForCellWithIdentifier:@"lineItemCell" cacheByIndexPath:indexPath configuration:^(LineItemCell *cell) {
                 cell.nameLabel.text = infoDic[@"project"];
            }];
        }
    }
    return 44;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}
#pragma mark -
#pragma mark - **************** 请求我的店铺服务列表
-(void)requestServerList
{
    [self.listArr removeAllObjects];
    NSMutableDictionary * requestInfo = [[NSMutableDictionary alloc]init];
    [PPNetworkHelper POST:app_person_myStore_serviceProjects parameters:requestInfo success:^(id responseObject) {
        if (YJPPSUCCESS(responseObject)) {
            for (NSDictionary * infoDic in responseObject[@"data"]) {
                [self.listArr addObject:infoDic];
            }
        }else{
            
        }
        [self.selfTableView reloadData];
    } failure:^(NSError *error) {
        
    } showLoading:nil];
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self requestServerList];
}
@end
